package com.daoliuhe.scaffold.web.controller.admin;

import com.daoliuhe.scaffold.model.RoleAuthoritiesRelation;
import com.daoliuhe.scaffold.service.RoleAuthoritiesRelationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/roleAuthoritiesRelation")
public class RoleAuthoritiesRelationController {

    private static final Logger logger = LoggerFactory.getLogger(RoleAuthoritiesRelationController.class);
    @Autowired
    RoleAuthoritiesRelationService roleAuthoritiesRelationService;

    /**
     * 根据用户查找角色
     *
     * @param auth
     * @return
     */
    @RequestMapping("/roleData")
    @ResponseBody
    public Object roleData(RoleAuthoritiesRelation auth) {
        logger.info("roleData,auth:{}", auth);
        return roleAuthoritiesRelationService.getRolePageData(auth);
    }

    @RequestMapping("/authData")
    @ResponseBody
    public Object authData(RoleAuthoritiesRelation auth) {
        logger.info("authData,auth:{}", auth);
        return roleAuthoritiesRelationService.getAuthPageData(auth);
    }

    /**
     * 保存用户角色关系
     *
     * @param auth
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public Object saveRelation(RoleAuthoritiesRelation auth) {
        logger.info("saveRelation,auth:{}", auth);
        return roleAuthoritiesRelationService.saveRelation(auth);
    }

    /**
     * 删除用户角色的关系
     *
     * @param authId
     * @param roleIds
     * @return
     */
    @RequestMapping("/deleteForAuth")
    @ResponseBody
    public Object deleteForAuth(String authId, String roleIds) {
        logger.info("deleteForAuth,authId:{},roleIds:{}", authId, roleIds);
        return roleAuthoritiesRelationService.deleteForAuth(authId, roleIds);
    }

    @RequestMapping("/deleteForRole")
    @ResponseBody
    public Object deleteForRole(String authIds, String roleId) {
        logger.info("deleteForRole,authIds:{},roleId:{}", authIds, roleId);
        return roleAuthoritiesRelationService.deleteForRole(authIds, roleId);
    }

    /**
     * 根据角色批量添加权限
     *
     * @param authIds
     * @param roleId
     * @return
     */
    @RequestMapping("/saveBatchAuthForRole")
    @ResponseBody
    public Object saveBatchAuthForRole(String authIds, String roleId) {
        logger.info("saveBatchAuthForRole,authIds:{},roleId:{}", authIds, roleId);
        return roleAuthoritiesRelationService.saveBatchAuthForRole(authIds, roleId);
    }

    /**
     * 根据权限批量添加角色
     *
     * @param authId
     * @param roleIds
     * @return
     */
    @RequestMapping("/saveBatchRoleForAuth")
    @ResponseBody
    public Object saveBatchRoleForAuth(String authId, String roleIds) {
        logger.info("saveBatchRoleForAuth,authId:{},roleIds:{}", authId, roleIds);
        return roleAuthoritiesRelationService.saveBatchRoleForAuth(authId, roleIds);
    }

}
